// $ANTLR 3.1.3 Mar 17, 2009 19:23:44 CSVLexer.g 2010-01-30 20:46:23
package org.concepts.java.antlr.csv;

import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

/**
 Lexer Grammar file
 -------------------
 
 Antlr breaks downs the works into different components. Lexer component 
 processes an input char stream into tokens. These tokens are processed by
 Parser component of Antlr. Tokens objects know their 
 start/stop stream index, line number, index within the line, and more. Lexer
 outputs/throws error if an undefined token is found in the input stream.
 
 In this example, we have to define the tokens for a comma separated list of
 integers (E.g. 4,56,98) that can be spread across multiple lines. User can
 also put Java style comments in the middle of this list. For more examples,
 look at TestCSV.java  

 The grammar file consists of a list of instructions. An instruction ends with
 ';'. Comments can be specified using the same syntax as Java.

 Besides defining the token specifications, in this example, we will
 also define grammar actions to customize the generated Lexer Java code.
 */
public class CSVLexer extends Lexer {
    public static final int NEWLINE=7;
    public static final int COMMA=4;
    public static final int MULTI_COMMENT=9;
    public static final int WHITESPACE=6;
    public static final int SINGLE_COMMENT=8;
    public static final int INT=5;
    public static final int EOF=-1;


      private int integerCount = 0;

      /**
      * Returns the number of integers in the list 
      */
      public int getIntegerCount() {
        return integerCount;
      }
      


    // delegates
    // delegators

    public CSVLexer() {;} 
    public CSVLexer(CharStream input) {
        this(input, new RecognizerSharedState());
    }
    public CSVLexer(CharStream input, RecognizerSharedState state) {
        super(input,state);

    }
    public String getGrammarFileName() { return "CSVLexer.g"; }

    // $ANTLR start "COMMA"
    public final void mCOMMA() throws RecognitionException {
        try {
            int _type = COMMA;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // CSVLexer.g:90:6: ( ',' )
            // CSVLexer.g:90:8: ','
            {
            match(','); 

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
    // $ANTLR end "COMMA"

    // $ANTLR start "INT"
    public final void mINT() throws RecognitionException {
        try {
            int _type = INT;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // CSVLexer.g:96:5: ( ( '0' .. '9' )+ )
            // CSVLexer.g:96:7: ( '0' .. '9' )+
            {
            // CSVLexer.g:96:7: ( '0' .. '9' )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( ((LA1_0>='0' && LA1_0<='9')) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // CSVLexer.g:96:7: '0' .. '9'
            	    {
            	    matchRange('0','9'); 

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);

            integerCount++;

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
    // $ANTLR end "INT"

    // $ANTLR start "WHITESPACE"
    public final void mWHITESPACE() throws RecognitionException {
        try {
            int _type = WHITESPACE;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // CSVLexer.g:104:11: ( ( ' ' | '\\t' )+ )
            // CSVLexer.g:104:13: ( ' ' | '\\t' )+
            {
            // CSVLexer.g:104:13: ( ' ' | '\\t' )+
            int cnt2=0;
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0=='\t'||LA2_0==' ') ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // CSVLexer.g:
            	    {
            	    if ( input.LA(1)=='\t'||input.LA(1)==' ' ) {
            	        input.consume();

            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        recover(mse);
            	        throw mse;}


            	    }
            	    break;

            	default :
            	    if ( cnt2 >= 1 ) break loop2;
                        EarlyExitException eee =
                            new EarlyExitException(2, input);
                        throw eee;
                }
                cnt2++;
            } while (true);

            _channel = HIDDEN;

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
    // $ANTLR end "WHITESPACE"

    // $ANTLR start "NEWLINE"
    public final void mNEWLINE() throws RecognitionException {
        try {
            int _type = NEWLINE;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // CSVLexer.g:110:8: ( ( ( '\\r' )? '\\n' )+ )
            // CSVLexer.g:110:10: ( ( '\\r' )? '\\n' )+
            {
            // CSVLexer.g:110:10: ( ( '\\r' )? '\\n' )+
            int cnt4=0;
            loop4:
            do {
                int alt4=2;
                int LA4_0 = input.LA(1);

                if ( (LA4_0=='\n'||LA4_0=='\r') ) {
                    alt4=1;
                }


                switch (alt4) {
            	case 1 :
            	    // CSVLexer.g:110:11: ( '\\r' )? '\\n'
            	    {
            	    // CSVLexer.g:110:11: ( '\\r' )?
            	    int alt3=2;
            	    int LA3_0 = input.LA(1);

            	    if ( (LA3_0=='\r') ) {
            	        alt3=1;
            	    }
            	    switch (alt3) {
            	        case 1 :
            	            // CSVLexer.g:110:11: '\\r'
            	            {
            	            match('\r'); 

            	            }
            	            break;

            	    }

            	    match('\n'); 

            	    }
            	    break;

            	default :
            	    if ( cnt4 >= 1 ) break loop4;
                        EarlyExitException eee =
                            new EarlyExitException(4, input);
                        throw eee;
                }
                cnt4++;
            } while (true);


            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
    // $ANTLR end "NEWLINE"

    // $ANTLR start "SINGLE_COMMENT"
    public final void mSINGLE_COMMENT() throws RecognitionException {
        try {
            int _type = SINGLE_COMMENT;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // CSVLexer.g:118:16: ( '//' (~ ( '\\r' | '\\n' ) )* NEWLINE )
            // CSVLexer.g:118:18: '//' (~ ( '\\r' | '\\n' ) )* NEWLINE
            {
            match("//"); 

            // CSVLexer.g:118:23: (~ ( '\\r' | '\\n' ) )*
            loop5:
            do {
                int alt5=2;
                int LA5_0 = input.LA(1);

                if ( ((LA5_0>='\u0000' && LA5_0<='\t')||(LA5_0>='\u000B' && LA5_0<='\f')||(LA5_0>='\u000E' && LA5_0<='\uFFFF')) ) {
                    alt5=1;
                }


                switch (alt5) {
            	case 1 :
            	    // CSVLexer.g:118:23: ~ ( '\\r' | '\\n' )
            	    {
            	    if ( (input.LA(1)>='\u0000' && input.LA(1)<='\t')||(input.LA(1)>='\u000B' && input.LA(1)<='\f')||(input.LA(1)>='\u000E' && input.LA(1)<='\uFFFF') ) {
            	        input.consume();

            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        recover(mse);
            	        throw mse;}


            	    }
            	    break;

            	default :
            	    break loop5;
                }
            } while (true);

            mNEWLINE(); 
            skip();

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
    // $ANTLR end "SINGLE_COMMENT"

    // $ANTLR start "MULTI_COMMENT"
    public final void mMULTI_COMMENT() throws RecognitionException {
        try {
            int _type = MULTI_COMMENT;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // CSVLexer.g:128:43: ( '/*' ( . )* '*/' ( NEWLINE )? )
            // CSVLexer.g:128:45: '/*' ( . )* '*/' ( NEWLINE )?
            {
            match("/*"); 

            // CSVLexer.g:128:50: ( . )*
            loop6:
            do {
                int alt6=2;
                int LA6_0 = input.LA(1);

                if ( (LA6_0=='*') ) {
                    int LA6_1 = input.LA(2);

                    if ( (LA6_1=='/') ) {
                        alt6=2;
                    }
                    else if ( ((LA6_1>='\u0000' && LA6_1<='.')||(LA6_1>='0' && LA6_1<='\uFFFF')) ) {
                        alt6=1;
                    }


                }
                else if ( ((LA6_0>='\u0000' && LA6_0<=')')||(LA6_0>='+' && LA6_0<='\uFFFF')) ) {
                    alt6=1;
                }


                switch (alt6) {
            	case 1 :
            	    // CSVLexer.g:128:50: .
            	    {
            	    matchAny(); 

            	    }
            	    break;

            	default :
            	    break loop6;
                }
            } while (true);

            match("*/"); 

            // CSVLexer.g:128:58: ( NEWLINE )?
            int alt7=2;
            int LA7_0 = input.LA(1);

            if ( (LA7_0=='\n'||LA7_0=='\r') ) {
                alt7=1;
            }
            switch (alt7) {
                case 1 :
                    // CSVLexer.g:128:58: NEWLINE
                    {
                    mNEWLINE(); 

                    }
                    break;

            }

            skip();

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
    // $ANTLR end "MULTI_COMMENT"

    public void mTokens() throws RecognitionException {
        // CSVLexer.g:1:8: ( COMMA | INT | WHITESPACE | NEWLINE | SINGLE_COMMENT | MULTI_COMMENT )
        int alt8=6;
        switch ( input.LA(1) ) {
        case ',':
            {
            alt8=1;
            }
            break;
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            {
            alt8=2;
            }
            break;
        case '\t':
        case ' ':
            {
            alt8=3;
            }
            break;
        case '\n':
        case '\r':
            {
            alt8=4;
            }
            break;
        case '/':
            {
            int LA8_5 = input.LA(2);

            if ( (LA8_5=='/') ) {
                alt8=5;
            }
            else if ( (LA8_5=='*') ) {
                alt8=6;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 8, 5, input);

                throw nvae;
            }
            }
            break;
        default:
            NoViableAltException nvae =
                new NoViableAltException("", 8, 0, input);

            throw nvae;
        }

        switch (alt8) {
            case 1 :
                // CSVLexer.g:1:10: COMMA
                {
                mCOMMA(); 

                }
                break;
            case 2 :
                // CSVLexer.g:1:16: INT
                {
                mINT(); 

                }
                break;
            case 3 :
                // CSVLexer.g:1:20: WHITESPACE
                {
                mWHITESPACE(); 

                }
                break;
            case 4 :
                // CSVLexer.g:1:31: NEWLINE
                {
                mNEWLINE(); 

                }
                break;
            case 5 :
                // CSVLexer.g:1:39: SINGLE_COMMENT
                {
                mSINGLE_COMMENT(); 

                }
                break;
            case 6 :
                // CSVLexer.g:1:54: MULTI_COMMENT
                {
                mMULTI_COMMENT(); 

                }
                break;

        }

    }


 

}